package khleuven.mondzorg.domain;

import org.json.JSONException;
import org.json.JSONObject;

public class JsonKeysDictionary {

	public static final String GOOGLE_DOCUMENT_NAME = "MondzorgData";
	
	public static final String PREFERRED_ENCODING = "UTF-8";//"iso-8859-1";
	
	public static final String JSON_KEY_GS_FEED = "feed";
	public static final String JSON_KEY_GS_ENTRY = "entry";	
	public static final String JSON_KEY_GS_TYPE = "type";		
	public static final String JSON_KEY_GS_ENTRY_LAST_MODIFIED_DATE ="updated";
	
	public static final String JSON_KEY_ITEM = "$t";
	public static final String JSON_KEY_LANGUAGE = "gsx$language";
	public static final String JSON_KEY_DESTINATION = "gsx$destinationgroup";
	public static final String JSON_KEY_ILLUSTRATIONS = "gsx$illustrationids";
	public static final String JSON_KEY_REVIEW = "reviewstatus";
	
	public static final String JSON_KEY_ENTRY_ID ="gsx$id";
	public static final String JSON_KEY_ENTRY_TYPE = "gsx$type";
	
	public static final String JSON_KEY_ILL_NAME = "gsx$naam";
	public static final String JSON_KEY_ILL_DESCRIPTION = "gsx$beschrijving";
	public static final String JSON_KEY_ILL_LINK = "gsx$illustratielink";
	public static final String JSON_KEY_ILL_BLOB = "gsx$blob";
	
	public static final String JSON_KEY_DEF_NAME = "gsx$definition";
	public static final String JSON_KEY_DEF_EXPLANATION = "gsx$explanation";
	
	public static final String JSON_KEY_FAQ_NAME = "gsx$faq";
	public static final String JSON_KEY_FAQ_EXPLANATION = "gsx$explanation";
	
	public static final String JSON_KEY_TEST_MODULE = "gsx$module";
	public static final String JSON_KEY_TEST_SEQUENCE = "gsx$seq";
	public static final String JSON_KEY_TEST_QUESTION = "gsx$question";
	public static final String JSON_KEY_TEST_ANSWERS = "gsx$answers";
	public static final String JSON_KEY_TEST_ANSWER = "gsx$answer";

	public static final String JSON_KEY_LEARN_LESSON = "gsx$lesson";
	
	
	public static String getStringItem(JSONObject object, String key) throws DomainException{
		try {
			return object.getJSONObject(key).getString(JSON_KEY_ITEM);
		} catch (JSONException e) {
			throw new DomainException("item not found", e);
		}
	}
	
	public static int getIntItem(JSONObject object, String key) throws DomainException{
		try {
			return object.getJSONObject(key).getInt(JSON_KEY_ITEM);
		} catch (JSONException e) {
			throw new DomainException("item not found", e);
		}
	}
	
	public static void toStringItem(JSONObject object, String key, String value) throws DomainException{
		try {
			JSONObject o = new JSONObject();
			o.put(JSON_KEY_ITEM, value);
			object.put(key, o);
		} catch (JSONException e) {
			throw new DomainException("JSON creation error", e);
		}
	}
	
	public static void toIntItem(JSONObject object, String key, int value) throws DomainException{
		try {
			JSONObject o = new JSONObject();
			o.put(JSON_KEY_ITEM, value);
			object.put(key, o);
		} catch (JSONException e) {
			throw new DomainException("JSON creation error", e);
		}
	}
}
